<template>
  <div class="h-naive-ui-login-box" :style="{backgroundImage: 'url(@/assets/login_bg.svg)'}">

  </div>
</template>
<script setup>
import { storeToRefs } from "pinia"
import { mainData } from "@/stores/index"
import router from "@/router"
import { ref, reactive } from "vue";
import useAxios from "@/config/js/AxiosConfig"
import { useMessage } from "naive-ui";
import { Glasses, GlassesOutline } from "@vicons/ionicons5";

let axios = useAxios()
let message = useMessage()

let piniaData = mainData()
let { webTitle, ifUserAuthority, userName } = storeToRefs(piniaData)

let loginData = reactive(
  {
    uname: null,
    upasswd: null
  }
)

let registData = reactive({
  uname: null,
  upasswd: null,
  qupasswd: null
})

/**
 * 登录方法
 */
function usersLogin() {
  // axios.post("/users/login", {
  //   uname: loginData.uname,
  //   upasswd: loginData.upasswd
  // },
  //   {
  //     headers: {
  //       'Content-Type': 'application/x-www-form-urlencoded'
  //     }
  //   }
  // ).then(function (res) {
  //   console.log(res);
  //   if (res.flag) {
  // userName.value = loginData.uname
  // ifUserAuthority.value = res.flag
  ifUserAuthority.value = true
  // message.success(res.message);
  router.push("/")
  //   } else {
  //     ifUserAuthority.value = res.flag
  //     message.error(res.message);
  //   }
  // }).catch(function (err) {
  //   console.log(err);
  // })
}

/**
 * 注册方法
 */
function usersRegister() {
  if (registData.uname !== null && registData.upasswd !== null && registData.qupasswd !== null) {
    if (registData.upasswd === registData.qupasswd) {
      axios.post("/users/register", {
        uname: registData.uname,
        upasswd: registData.upasswd
      })
        .then(res => {
          if (res.flag) {
            message.success(res.message);
          } else {
            message.error(res.message);
          }
        })
        .catch(err => {
          console.error(err);
        })
    } else {
      message.error("请在次确认重复密码是否正确！");
    }
  } else {
    console.log("错误");
  }
}
</script>
<style scoped>
@import url("@/styles/ViewCss/LoginView.css");
</style>